import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { OrganizationConst } from "src/consts/organization_const";

@Component({})
export default class OrgPanel extends MyVue {
    name: string = 'OrgPanel';
    formData: any;
    footerFlag: boolean = true;
    beforeCreate(): void {
    }

    initData(that?: any): void {
        that.formData = WLStore().state.orgShow;
    }

    mounted(): void {
    }


    editOrg(): void {
        this.$refs.orgForm.validate((valid: Boolean) => {
            if (valid) {
                WLDispatch(OrganizationConst.DispatchOrgEdit, this.formData);
            } else {
                WLMessage("必填字段为空,无法编辑部门", "warning")
                return false;
            }
        })
    }

    rowDelete(index: Number, data: any): void {
        this.$confirm(`是否删除成员：${data.name}?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            WLDispatch(OrganizationConst.DispatchOrgShowListDelAcc, data.id)
        }).catch(() => { })
    }

    doNew(): void {
        let senData: any = {}
        senData["curr_page"] = 1
        senData["page_size"] = 9999
        WLDispatch(OrganizationConst.DispatchOrgAcc, senData);
    }

    doReSet(): void {
        this.$confirm(`确定清空所有成员?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            var list = this.formData.mem_list.slice(0)
            if (isNoEmpty(list)) {
                for (let i = 0; i < list.length; i++) {
                    if (list[i]) {
                        WLDispatch(OrganizationConst.DispatchOrgShowListDelAcc, list[i].id);
                    }
                }
            }
        }).catch(() => { })
    }

    rowClassName(data: any): string {
        if (data.row.selected) {
            return 'selected_row';
        }
        return '';
    }
}